import logging


# log记录日志
class Log:
    def __init__(self, name, log_file, level=logging.INFO):
        self.name = name
        self.log_file = log_file
        self.level = level
        self.logger = self._create_logger()

    def _create_logger(self):
        logger = logging.getLogger(self.name)
        logger.setLevel(self.level)
        handler = logging.FileHandler(self.log_file, encoding='utf-8')
        formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        handler.setFormatter(formatter)
        logger.addHandler(handler)
        return logger


    def info(self, info):
        self.logger.info(info)


log = Log(name='my_log', log_file='logs/log.txt')
traffic_log = Log(name='traffic_log', log_file='logs/traffic_log.txt')